- main_toolbar do |t|
  = t.edit resource
  - budget = resource.budget_of(current_campaign)
  - if budget && budget.items.any?
    = tool_to(:edit_budget.tl, { controller: :activity_budgets, action: :edit, id: budget.id })
  - if current_campaign && resource.productions.of_campaign(current_campaign).empty?
    = tool_to(:close.ta, { controller: :campaigns, action: :close, id: current_campaign.id, activity_id: resource.id, redirect: url_for(controller: :campaigns, action: :show, id: current_campaign.id) }, method: :delete, data: { confirm: :are_you_sure.tl }, tool: :remove)

  - if resource.decorate.animal_family? && resource.productions.any? && Product.of_variety(resource.cultivation_variety, resource.support_variety).any?
    = tool_to(:distribute_unaffected_products.tl, { controller: :products, action: :edit_many, activity_id: resource.id }, icon: false)

  = t.export :land_parcel_register, key: Printers::LandParcelRegisterActivityPrinter.build_key(campaign: current_campaign, activity: @activity), label: :print_land_parcel_register

- main_period_selector(:year)


= main_informations attachment: true do
  .big-infos
    .med-info.important
      %span.title= :net_surface_area.tl
      %span.value= resource.decorate.human_net_surface_area(current_campaign)

    .med-info.important
      %span.title= :working_area.tl
      %span.value= resource.decorate.human_working_zone_area(current_campaign)
    - unless @reentry_possible.possible
      .med-info.delay
        %span.title= :re_entry_delay.tl
        %span.value
          %span= @reentry_possible.next_possible_date

  = attributes_list do |l|
    - l.attribute :production_system
    - l.attribute :use_countings
    - l.attribute :use_gradings
    - l.attribute :use_seasons
    - l.attribute :use_tactics
    -# if resource.use_gradings
      - l.attribute :measure_grading_net_mass
      - if resource.measure_grading_net_mass
        - l.attribute :grading_net_mass_unit
      - l.attribute :measure_grading_sizes
      - if resource.measure_grading_sizes
        - l.attribute :grading_sizes_indicator
        - l.attribute :grading_sizes_unit

= cobbles do |c|

  - if current_campaign
    - c.cobble :budget do
      = render 'budget'
  -# c.cobble :details do
    = attributes_list do |l|
      - l.attribute :nature
      - l.attribute :family
      - l.attribute :production_system_name
      - if resource.with_cultivation
        - l.attribute :cultivation_variety
      - if resource.with_supports
        - l.attribute :support_variety
      - l.attribute :production_cycle

  - if resource.plant_farming? && resource.productions.of_campaign(current_campaign).any?

    - inspection_data = nil
    - if resource.inspectionable?
      - dimension = resource.unit_preference(current_user)
      - inspection_data = inspection_series(dimension, resource.inspections)

    - c.cobble :map do
      - data = support_series(resource)
      - if data.empty?
        .placeholding-message= :no_production_defined_for_current_campaign.tn
      - else
        = visualization(optional_data_url: backend_visualizations_non_treatment_areas_visualizations_path) do |v|
          - v.serie :main, data
          - v.simple :support, :main
          - if !inspection_data.blank?
            - v.serie :inspection, inspection_data
            - v.categories :ready_to_harvest, :inspection, without_ghost_label: true
            - v.choropleth :disease_percentage, :inspection, stop_color: "#FF0000"
            - v.choropleth :deformity_percentage, :inspection, stop_color: "#FFB300"
          - v.control :zoom
          - v.control :scale
          - v.control :fullscreen
          - v.control :layer_selector

  - c.cobble(:production_costs, title: :production_costs.tl) do
    = render partial: 'backend/shared/production_costs', locals: { costs: resource.decorate.production_costs(current_campaign) }

  - if resource.with_supports
    - c.cobble(:productions) do
      = render 'productions'

  - if resource.auxiliary? && resource.distributions.any?
    - c.cobble(:distributions, title: Activity.human_attribute_name(:distributions)) do
      :ruby
        resource.distributions.reorder(:affectation_percentage).find_each.map do |distribution|
          percentage = distribution.affectation_percentage.to_s.to_f
          { name: :label_value.th(label: distribution.main_activity_name, value: number_to_percentage(y, precision: 2)), y: percentage }
        end
        series = [{type: 'pie', name: Activity.human_attribute_name(:distributions), data: data}]

      = pie_highcharts(series, legend: true)

  - if resource.inspectionable?
    - dimension  = resource.unit_preference(current_user)
    - async_cobble :stock_in_ground, params: { id: resource.id, dimension: dimension }, cobble: c  do
      = render 'backend/inspections/unit_selector', activity: resource

  - if resource.inspectionable?
    - c.cobble(:inspections) do
      - if @crops.resultset.any?
        = list_settings_toolbar(menu_up: true)
      .toolbar
        = link_to :new_inspection.tl, new_backend_inspection_path(activity_id: @activity.id), class: "btn btn-default icn btn-new"

      - if @crops.resultset.any?
        = render partial: 'crops'
